package com.hedl.practice.diyJava.multithreading.thread_pool.thread_pool_test;

import com.hedl.practice.diyJava.multithreading.thread_pool.thread_pool_test.utils.Task;

import java.time.LocalDateTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class StudyThreadPool_1 {
    public static void main(String[] args) {
        /**
         * ScheduledExecutorService 继承了 ExecutorService 继承了 Executor
         */
        ScheduledExecutorService ses = Executors.newScheduledThreadPool(4);
        LocalDateTime ldt = LocalDateTime.now();
        //ses.schedule(new Task("one-time"),1, TimeUnit.SECONDS);     //1秒后执行一次性任务:
        //ses.scheduleAtFixedRate(new Task("fixed-rate"),2,3,TimeUnit.SECONDS);   // 2秒后开始执行定时任务，每3秒执行:

        System.out.println("开始时间："+ldt);
        ses.scheduleWithFixedDelay(new Task("fixed-delay"),2,3,TimeUnit.SECONDS);   // 2秒后开始执行定时任务，以3秒为间隔执行:
    }
}
